package com.zzc.legou.search.controller;

import com.zzc.legou.search.service.SearchService;
import com.zzc.legou.search.vo.SearchRequest;
import com.zzc.legou.search.vo.SearchResult;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/search")
public class SearchController {

    @Autowired
    private SearchService searchService;

    @ApiOperation(value = "查询方法")
    @PostMapping("/query")
    public ResponseEntity<SearchResult> query(@RequestBody SearchRequest request) {
        SearchResult searchResult = searchService.searchQuery(request);
        if (!ObjectUtils.isEmpty(searchResult)) {
            return ResponseEntity.ok(searchResult);
        } else {
            return new ResponseEntity<>(HttpStatus.NO_CONTENT);
        }
    }
}
